package com.gitee.ywj1352.mongodb;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;

/**
 * @author wenjie.yang on 2019/6/25.
 */
//@Slf4j
public class MongoDBDemo {
    /**
     * 它是最想关系型数据库 的非关系型数据库
     * 迁移会遇到一些问题
     * 不要滥用,
     */
    public MongoDBDemo() {
    }

    public static MongoDatabase getClient(String collections) {
        MongoClient mongoClient = MongoClients.create("mongodb://localhost:27017");
        MongoDatabase testdb;
        if (collections == null) {
            testdb = mongoClient.getDatabase("testdb");
        } else {
            testdb = mongoClient.getDatabase(collections);
        }
        return testdb;
    }

//    public static void main(String[] args) {
//        MDC.put("THREAD_ID", String.valueOf(Thread.currentThread().getId()));
//        MongoDatabase testdb =getClient(null);
//        MongoCollection<Document> testdb1 = testdb.getCollection("testdb");
//        Document document = new Document();
//        document.put("name", "evant");
//        document.put("age", "25");
//        document.put("address", "shanxi");
//        testdb1.insertOne(document);
//        log.info("哈哈哈");
//    }





}
